<template>
  <div class="order-list">
    <el-table :data="orderList" style="width: 100%" v-loading="loading">
      <el-table-column prop="orderNumber" label="订单编号"/>
      <el-table-column prop="status" label="订单状态"/>
      <el-table-column prop="packageWeight" label="包裹重量(kg)"/>
      <el-table-column prop="packageVolume" label="包裹体积(m³)"/>
      <el-table-column prop="estimatedDeliveryTime" label="预计送达时间"/>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="viewOrder(scope.row)">查看</el-button>
          <el-button size="mini" type="primary" @click="editOrder(scope.row)">编辑</el-button>
          <el-button size="mini" type="danger" @click="deleteOrder(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { listOrders, delOrders } from '@/api/system/orders'

export default {
  name: 'OrderList',
  data() {
    return {
      orderList: [],
      loading: true
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    getOrderList() {
      this.loading = true
      listOrders().then(response => {
        this.orderList = response.rows
        this.loading = false
      })
    },
    viewOrder(row) {
      this.$router.push({ path: '/order/detail', query: { orderId: row.orderId }})
    },
    editOrder(row) {
      this.$router.push({ path: '/order/edit', query: { orderId: row.orderId }})
    },
    deleteOrder(row) {
      this.$modal.confirm('是否确认删除订单编号为"' + row.orderNumber + '"的数据项?').then(() => {
        return delOrders(row.orderId)
      }).then(() => {
        this.getOrderList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    }
  }
}
</script> 